package com.lagou.service;

import com.lagou.pojo.Article;
import com.lagou.repository.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class ArticleService {
    @Autowired
    private ArticleRepository repository;

    @Cacheable(cacheNames = "article")
    public Page<Article> selectList(int page, int size){
        Sort sort = Sort.by(Sort.Direction.DESC,"id");
        Pageable pageRequest = PageRequest.of(page, size, sort);
        Page<Article> all = repository.findAll(pageRequest);
        return all;
    }

}
